﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace FIMQueryTool
{
    public class UIData
    {
        // Create a logger for use in this class.
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public string ObjectType;
        public bool FilterAttributesAll;
        public List<string> FilterAttributes = new List<string>();
        public string ReferenceFormat;
        public string Query;

        public string ToXml()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(this.GetType());
            StringWriter stringWriter = new StringWriter();
            xmlSerializer.Serialize(stringWriter, this);
            string serializedXML = stringWriter.ToString();
            return serializedXML;
        }

        public static UIData FromXml(string filePath)
        {
            UIData result = null;
            XmlSerializer serializer = new XmlSerializer(typeof(UIData));
            using (StreamReader reader = new StreamReader(filePath))
            {
                result = (UIData)serializer.Deserialize(reader);
            }
            return result;
        }
    }
}
